package com.funromania.server.security.shiro;

import java.lang.reflect.Method;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.shiro.authz.aop.RoleAnnotationMethodInterceptor;

public class ShiroMethodInterceptor implements MethodInterceptor {

	private final RoleAnnotationMethodInterceptor roleAnnotationMethodInterceptor = new RoleAnnotationMethodInterceptor();

	public Object invoke(MethodInvocation methodInvocation) throws Throwable {
		return roleAnnotationMethodInterceptor
				.invoke(new ShiroMethodInvocation(methodInvocation));
	}

	private static class ShiroMethodInvocation implements
			org.apache.shiro.aop.MethodInvocation {

		private final MethodInvocation methodInvocation;

		public ShiroMethodInvocation(MethodInvocation methodInvocation) {
			this.methodInvocation = methodInvocation;
		}

		public Object[] getArguments() {
			// TODO Auto-generated method stub
			return methodInvocation.getArguments();
		}

		public Method getMethod() {
			return methodInvocation.getMethod();
		}

		public Object getThis() {
			return methodInvocation.getThis();
		}

		public Object proceed() throws Throwable {
			return methodInvocation.proceed();
		}
	}
}